{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form gg-form-bar border-t border-x">

    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="pName" placeholder="供应商" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="buyUnit" placeholder="采购单位" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="buyName" placeholder="采购员" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="orderNum" placeholder="采购单号" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="xsHt" placeholder="销售单号" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="brand" placeholder="品牌" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="specs" placeholder="规格型号" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="buyCode" placeholder="订货号" class="layui-input" autocomplete="off" />
    </div>
<!--    <div class="layui-input-inline" style="width:300px;">-->
<!--        <select name="status" >-->
<!--            <option value="">所有状态</option>-->
<!--            {foreach ['','草稿','已确认']  as $key=>  $v}-->
<!--            <option value="{$key}">{$v}</option>-->
<!--            {/foreach}-->
<!--        </select>-->
<!--    </div>-->
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="orderDate" placeholder="单据日期" readonly id="orderDate" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="hsContract" placeholder="货商合同" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:150px;">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform"><i class="layui-icon layui-icon-search mr-1"></i>搜索</button>
        <button type="reset" class="layui-btn layui-btn-reset" lay-filter="reset">清空</button>
    </div>
</form>
<div class="p-3">
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
<!--        <button class="layui-btn layui-btn-sm addNew" lay-event="locks" type="button">锁定</button>-->

<!--        <a href="javascript:" class="layui-btn layui-btn-sm layui-btn-primary" lay-event="cg" >采购</a>-->
<!--        <a href="javascript:" class="layui-btn layui-btn-sm layui-btn-primary" lay-event="ck" >出库</a>-->
<!--        <a href="javascript:" class="layui-btn layui-btn-sm layui-btn-primary" lay-event="refund" >退货</a>-->
<!--        <a href="{:url('api/ExportModel/SaleContractImportModel')}" target="_blank" class="layui-btn layui-btn-sm layui-btn-primary">导入模板</a>-->
<!--        <button class="layui-btn layui-btn-sm layui-btn-danger del" lay-event="del" type="button">删除</button>-->
        <!--      <a class="layui-btn layui-btn-sm layui-btn-normal " target="_blank" href="{:url('exportData')}">导出</a>-->
    </div>
</script>
<script type="text/html" id="actionBar">


<!--    <button class="layui-btn layui-btn-normal  layui-btn-xs" lay-event="edit">编辑</button>-->
<!--    <button class="layui-btn layui-btn-normal  layui-btn-xs" lay-event="detail">详情</button>-->
    <!--    <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>-->
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool'];
    let statusArr=['','草稿','已确认','待审批','已通过','已拒绝'];
    let payStatusArr=['','未回款','部分回款','全部汇款'];
    function gouguInit() {
        var table = layui.table, tool = layui.tool, form = layui.form;
        var upload=layui.upload;
        layui.laydate.render({
            elem:'#orderDate',
            range:'~'
        })
        var tableIns = table.render({
            elem: '#test'
            ,toolbar: '#toolbarDemo'
            // ,defaultToolbar:  ['filter',  'exports']
            ,title:'采购合同'
            ,url: "{:url('index')}"
            ,page: true
            ,cellMinWidth: 80
            ,cols: [[
                {type: 'checkbox', fixed: 'left' },
                {fixed: 'left',field: 'id',title: 'ID' ,unresize: true,hide:true},
                {field:'orderNum', title: '采购单号', align:'center'},
                {field:'hsContract', title: '货商合同', align:'center'}
                ,{field:'pName',title: '供应商'}
                ,{field:'cgdw',title: '采购单位'}
                ,{field:'saleName',title: '采购员'}
                ,{field:'mdName',title: '品名'}
                // ,{field:'bar_code',title: '物料编码'}
                ,{field:'brand',title: '品牌'}
                ,{field:'specs',title: '型号'}
                ,{field:'buyCode',title: '订货号'}
                ,{field:'unit',title: '单位'}
                ,{field:'bjNum',title: '数量'}
                ,{field:'bjPrice',title: '含税单价'}
                ,{field:'noTaxPrice',title: '未税单价'}
                ,{field:'bjMoney',title: '含税小计'}
                ,{field:'savedMoney',title: '已付金额'}
                ,{field:'savedProp',title: '已付比例'}
                ,{field:'invoiceMoney',title: '已收票金额'}
                // ,{field:'noTaxMoney',title: '未税总额'}
                // ,{field:'taxMoney',title: '税额'}
                ,{field:'remark',title: '备注'}
                ,{field:'inNum',title: '已入库数量'}
                ,{field:'ztNum',title: '在途数量'}
                ,{field:'refundNum',title: '已退货数量'}
                ,{field:'orderDate',title: '合同单据时间'}
                ,{field:'saleContractOrderNum',title: '销售合同'}
                // ,{title: '操作',fixed: 'right',width: 200, align:'center', toolbar: '#actionBar'}
            ]]
        });
        //监听搜索提交
        form.on('submit(webform)', function (data) {
            console.log('data',data)
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });
        table.on('tool(test)',function (obj) {
            if(obj.event === 'edit'){
                tool.side("{:url('add')}?id=" + obj.data.id);
            }
            if(obj.event === 'detail'){
                tool.side("{:url('info')}?id=" + obj.data.id);
            }

            if (obj.event === 'del') {
                layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function (index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            obj.del();
                        }
                    }
                    tool.delete("{:url('delete')}", {id: obj.data.id}, callback);
                    layer.close(index);
                });
            }
        });
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            console.log(checkStatus)
            switch(obj.event){
                case 'locks':
                    var data = checkStatus.data;
                    var ids=[]
                    if (data.length) {
                        data.forEach(function (value, index) {
                            console.log('value', value)
                            ids.push(value.id)
                        })
                        if (ids.length!=1){
                            layer.msg('职能选择一条数据');
                            return;
                        }
                        tool.side("{:url('lock')}?sdId="+ids[0]);
                    }else {
                        layer.msg('请选择数据');
                    }
                    break;
                case 'cg':
                    var data = checkStatus.data;
                    var ids=[]
                    if (data.length){
                        data.forEach(function (value,index) {
                            console.log('value',value)
                            ids.push(value.id)
                        })
                        tool.side("{:url('toBuy')}?ids="+ids.join(','))
                    }else {
                        layer.msg('请选择数据');
                    }

                    break;
                case 'ck':
                    var data = checkStatus.data;
                    var ids=[]
                    if (data.length){
                        data.forEach(function (value,index) {
                            console.log('value',value)
                            ids.push(value.id)
                        })
                        tool.side("{:url('toOut')}?ids="+ids.join(','))

                    }else {
                        layer.msg('请选择数据');
                    }

                    break;
                case 'refund':
                    var data = checkStatus.data;
                    var ids=[]
                    if (data.length){
                        data.forEach(function (value,index) {
                            console.log('value',value)
                            ids.push(value.id)
                        })

                        tool.side("{:url('toRefund')}?ids="+ids.join(','))
                    }else {
                        layer.msg('请选择数据');
                    }

                    break;

            };
        })

        var loadingIndex='';
        upload.render({
            elem: '#import'
            ,url: "{:url('importData')}"
            ,accept: 'file'
            ,exts: 'xlsx',
            before:function (res) {
                loadingIndex=layer.load(1,{
                    shade: [0.5,'#a09b9b']
                });
            }
            ,done: function(res){
                layer.msg(res.msg)
                layer.close(loadingIndex)
                setTimeout(function () {
                    location.reload()
                },2000)
            },
            error(e){
                layer.msg('网络异常请稍后再试')
                layer.close(loadingIndex)
            }
        });

    }
</script>
{/block}
<!-- /脚本 -->